-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Unit tests for Pyodide #697
base: master
Are you sure you want to change the base?
Create Unit tests for Pyodide #697
Conversation
@leandro-benedet-garcia Could you give me access to push to your fork? I've got this approach working, at least locally. Or you can just pull the changes yourself from |
@henryiii I added you to the fork, I tried with just pull request but in the CI it showed the same error. |
Ahhh, good point, I can just run the CI on my fork first. The problem you are seeing is that you can't import the modules you are building during the compilation phase when cross-compiling. Only later via WASM. So we need to be able to disable the subgen tests. (Well, easily, anyway. There are ways to set the cross-compiling emulator in CMake) |
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
@leandro-benedet-garcia can you add me too? |
Actually it seems to work now. |
endif() | ||
install( | ||
TARGETS | ||
inter_module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a bit too much repetition of test names in this project. How about defining them as a list and then creating the build and install targets by pasting the list or iterating over elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love list(TRANSFORM
(CMake 3.12+) :)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Allrighty, since it seems to be working now I will put it for review, thank you @henryiii |
Let me know if you have questions about any of the changes! Very high level, I made the find_package(Python) GLOBAL, since it was not usable outside the directory it's triggered from, but the If you want to try out out locally without Emscripten, you can do something like this: pipx run build --wheel
uv venv
uv pip install dist/nanobind_tests-0.0.1-cp312-cp312-macosx_14_0_x86_64.whl
py -m pytest |
What's the status of this PR? Anything left to do, should I review? |
it is ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A first round of feedback / questions.
One high level thing that I did not like is how this change seems to elevate the tests/CMakeLists.txt
into its own top-level makefile that recursively includes the parent. It seems hacky to me and makes things more difficult to understand when reading through the CMake code.
What's special about Emscripten that it cannot follow the previous pattern?
@@ -155,7 +155,8 @@ if (NOT TARGET Python::Module OR NOT TARGET Python::Interpreter) | |||
|
|||
find_package(Python 3.8 | |||
REQUIRED COMPONENTS Interpreter ${NB_PYTHON_DEV_MODULE} | |||
OPTIONAL_COMPONENTS Development.SABIModule) | |||
OPTIONAL_COMPONENTS Development.SABIModule | |||
GLOBAL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this GLOBAL parameter exists starting in CMake 3.24, while this file declares
cmake_minimum_required(VERSION 3.15...3.27)
What are the implications?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to try to experiment a bit here in a day or two and see if I can either make the test subdirectory build nicer or build from the parent directory.
@@ -228,9 +233,10 @@ function (nanobind_build_library TARGET_NAME) | |||
${NB_DIR}/ext/robin_map/include) | |||
endif() | |||
|
|||
get_property(nanobind_python_headers TARGET Python::Module PROPERTY INTERFACE_INCLUDE_DIRECTORIES) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the style of the rest of the code, how about renaming this to NB_PYTHON_HEADERS
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also like to know: under what conditions does the new code lead to behavior that is different from what was there before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the headers and targets are not defined, then this produces an error, while the other one silently adds an empty string and proceeds to fail much later with a Python.h not found error.
@@ -275,6 +281,9 @@ function (nanobind_compile_options name) | |||
if (MSVC) | |||
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/bigobj /MP>) | |||
endif() | |||
if (CMAKE_SYSTEM_NAME MATCHES Emscripten) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line needed? We already declared this as a PUBLIC
exported flag of the nanobind library target, which is also inherited by anything else consuming the target.
@@ -1,11 +1,32 @@ | |||
include_guard(GLOBAL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line seems superfluous, nobody will double-include this file.
@@ -1,11 +1,32 @@ | |||
include_guard(GLOBAL) | |||
|
|||
cmake_minimum_required(VERSION 3.15...3.27) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about these lines. It looks to me like this sets up an independent top-level project, but I don't understand why. The tests/CMakeLists.txt
file is part of the parent CMakeLists.txt
build system.
cmake_minimum_required(VERSION 3.15...3.27) | ||
project(nanobind_tests LANGUAGES CXX) | ||
|
||
if(PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks complicated to me, and I don't understand why it is needed.
For emscripten, you have to build the test module as a wheel and then test it. There are two ways to do that. In pybind11, we make the test module buildable. The other option would be to have a way to enable tests to be build as the wheel in the outer pyproject.toml. Names can't be changed, so you couldn't have both at the same time, but I think you could use the tests/pyproject.toml but the main CMakeLists.txt - would have to investigate. This would require fewer changes, but I was just updating this PR, which started with the test module buildable (and that does mimic pybind11. But in pybind11 we haven't moved to scikit-build-core yet for the outer build). I can try the other method in a couple of days. |
f9e5e0b
to
30e96b7
Compare
Any progress on restructuring the PR? Should I close it for now? |
I will try my hand at it this weekend. |
f3e2796
to
bff96e2
Compare
Hello, as I mentioned in #687 I am creating unit tests for Pyodide, however, I am creating as a draft because I am going to actually need some assistance as I don't know very well this code base.
Currently I am going trough the route of pybind11 with a pyproject.toml, did some changes in the Cmake file of nanobind in the tests, but for some reason, every time I try to build the tests, I get this error:
Which, I don't know if I am doing something wrong, or a bug, because I don't see anything special related to Pyodide/Emscripten in the Cmake test in pybind11